package com.jiao.testdemo.pattern.mediator;

/**
 * TODO(文件概要)
 *
 * <p> TODO(具体描述信息,可以不填)
 *
 * @author meetsocial
 * @version V1.0
 * @className: ConcreteMediator
 * @date 2024/11/15 10:50
 */
public class ConcreteMediator implements Mediator{
    private ComponentA componentA;
    private ComponentB componentB;

    public void setComponentA(ComponentA componentA) {
        this.componentA = componentA;
    }

    public void setComponentB(ComponentB componentB) {
        this.componentB = componentB;
    }

    @Override
    public void notify(Component sender, String event) {
        if (sender == componentA) {
            componentB.handleEvent(event);
        } else if (sender == componentB) {
            componentA.handleEvent(event);
        }
    }

}
